package com.nl.controller.web.controller;

import com.nl.controller.common.model.Response;
import com.nl.controller.common.util.ResponseUtil;
import com.nl.controller.web.service.ResetPassWordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@Slf4j
@RequestMapping("reset")
public class ResetPasswordController {
    @Autowired
    private ResetPassWordService resetPassWordService;

    @PostMapping("judge")
    public Response judgeUser(
            HttpSession session,
            @RequestParam("msisdn") String msisdn

    ) {
        String result = resetPassWordService.judgeMsisdn(msisdn);
        log.info("重置密码参数(确认账户是否存在)：{}", msisdn);
        log.debug("重置密码参数(确认账户是否存在)返回数据：{}", result);
        return ResponseUtil.sucess(result);
    }

    @PostMapping("reset")
    public Response login(
            HttpSession session,
            @RequestParam("msisdn") String msisdn,
            @RequestParam("password") String password
    ) {
        int result = resetPassWordService.resetPassword(msisdn, password);
        log.info("重置密码参数：{}", msisdn + " " + password);
        log.debug("重置密码参数返回数据：{}", result);
        return ResponseUtil.sucess(result);
    }
}
